package tuilayer;
import java.util.*;
import modelLayer.*;

public class ValidateInput {
    private static boolean valid;
    
    public static boolean validateID(int check) {
        PersonContainer personContainer = PersonContainer.getInstance();
        if(personContainer.getPerson(check) != null)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static int readInt(String complain) {
        Scanner keyboard = new Scanner(System.in);
        int id = 2146984762;
        while(id == 2146984762) {
            if(keyboard.hasNextInt())
                id = keyboard.nextInt();
            else {
                keyboard.nextLine();
                System.out.println("\nPlease provide valid input.");
                System.out.println(complain);
            }            
        }
        return id;
    }

    public static boolean validateInt(int check) {
        if(check >= 0)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean isInteger(String s) {
        try { 
            Integer.parseInt(s); 
        } catch(NumberFormatException e) { 
            return false; 
        }
        return true;
    }
    
    public static boolean validateName(String check) {
        if(check.length() >= 2 && check.length() <= 30)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateAddress(String check) {
        if(check.length() >= 10 && check.length() <= 100)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validatePostalCode(String check) {
        if(check.length() >= 6 && check.length() <= 12)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateCity(String check) {
        if(check.length() >= 2 && check.length() <= 156)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validatePhoneNumber(String check) {
        if(check.length() >= 8 && check.length() <= 15)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateBorrowDate(String check) {
        if(check.length() >= 6 && check.length() <= 15)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validatePeriod(String check) {
        if(check.length() >= 6 && check.length() <= 15)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateDVDCopy(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.findCopy(check) != null)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateDVDCopyAvailability(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.findCopy(check).getStatus().equals("available"))
            valid = true;
        else
            valid = false;
        return valid;
    }

    public static boolean validateDVDTitle(String check) {
        if(check.length() >= 2 && check.length() <= 30)
            valid = true;
        else
            valid = false;
        return valid;
    }

    public static boolean validateNewBarcode(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.getDVD(check) != null)
            valid = false;
        else
            valid = true;
        return valid;
    }

    public static boolean validateBarcode(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.getDVD(check) != null)
            valid = true;
        else
            valid = false;
        return valid;
    }

    public static boolean validateDVDArtist(String check) {
        if(check.length() >= 2 && check.length() <= 30)
            valid = true;
        else
            valid = false;
        return valid;
    }

    public static boolean validateDVDPublicationDate(String check) {
        if(check.length() >= 6 && check.length() <= 15)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateNewSerialNumber(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.findCopy(check) != null)
            valid = false;
        else
            valid = true;
        return valid;
    }

    public static boolean validateSerialNumber(int check) {
        DVDContainer dvdContainer = DVDContainer.getInstance();
        if(dvdContainer.findCopy(check) != null)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validatePurchaseDate(String check) {
        if(check.length() >= 6 && check.length() <= 15)
            valid = true;
        else
            valid = false;
        return valid;
    }
    
    public static boolean validateLoanID(int check) {
        LoanContainer loanContainer = LoanContainer.getInstance();
        if(loanContainer.getLoan(check) != null)
            valid = true;
        else
            valid = false;
        return valid;
    }
}
